 package CurtainDesign;

 import CurtainDesign.utils.CurtainChecker;
 import CurtainDesign.utils.Translator;
 import NewOrderXmlbean.Comments;
 import NewOrderXmlbean.Levelinfo;
 import NewOrderXmlbean.OrderDocument;
 import NewOrderXmlbean.OrderDocument.Factory;
 import NewOrderXmlbean.Orderinfo;
 import java.io.File;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import javax.swing.JOptionPane;

 public class OrderFileByPass extends OrderFile
 {
   public boolean ReadOrderFile(String orderfile)
   {
     try
     {
       File xmlfile = new File(orderfile);
       OrderDocument doc = OrderDocument.Factory.parse(xmlfile);
       Orderinfo orderinfo = doc.getOrder();
       Translator.english2Chinese(orderinfo);
       Levelinfo level = orderinfo.getLevelArray(0);

       String tmp = orderinfo.getWindowtype();
       if (!CurtainChecker.isEmpty(tmp)) {
         int index = -1;
         for (int i = 0; i < Constants.STYLES.length; i++) {
           if (tmp.equals(Constants.STYLES[i])) {
             index = i;
             break;
           }
         }
         if (index > -1) {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveStyle(index);
         }
       }
       else
       {
         JOptionPane.showMessageDialog(null, "读取WindowType错误，请检查", "读文件错误", 0);
         return false;
       }

       tmp = orderinfo.getOrderindex();
       if (!CurtainChecker.isEmpty(tmp)) {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveOrderIndex(tmp);
       }
       else {
         JOptionPane.showMessageDialog(null, "读取OrderIndex错误，请检查", "读文件错误", 0);
         return false;
       }

       tmp = orderinfo.getClientregion();
       if (!CurtainChecker.isEmpty(tmp)) {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveClientRegion(tmp);
       }
       else {
         JOptionPane.showMessageDialog(null, "读取ClientRegion错误，请检查", "读文件错误", 0);
         return false;
       }

       tmp = orderinfo.getRoom();
       if (!CurtainChecker.isEmpty(tmp)) {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveRoom(tmp);
       }
       else {
         JOptionPane.showMessageDialog(null, "读取Room错误，请检查", "读文件错误", 0);
         return false;
       }

       tmp = orderinfo.getPipeindex();
       if (!CurtainChecker.isEmpty(tmp)) {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SavePipeIndex(tmp);
       }
       else
       {
         String tmppipe = CurtainDesign.m_PipeIndexFile.GetPipeIndex(Constants.STYLES[2], true);
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SavePipeIndex(tmppipe);
       }

       tmp = orderinfo.getOrderdate();
       if (!CurtainChecker.isEmpty(tmp)) {
         DateFormat dtformat = new SimpleDateFormat("ddMMyyyy");
         Date date = dtformat.parse(tmp);
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveOrderDate(date);

         long lDate = date.getTime() + 691200000L;
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDeliverDate(new Date(lDate));
       }
       else {
         JOptionPane.showMessageDialog(null, "读取Order Date错误，请检查", "读文件错误", 0);
         return false;
       }

       tmp = orderinfo.getCustomerrefnum();
       if (!CurtainChecker.isEmpty(tmp)) {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().saveCustRefNum(tmp);
       }

       tmp = orderinfo.getWindownum();
       if (!CurtainChecker.isEmpty(tmp)) {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveWindowNum(tmp);
       }
       else {
         JOptionPane.showMessageDialog(null, "读取WindowNum错误，请检查", "读文件错误", 0);
         return false;
       }

       tmp = orderinfo.getWindowindex();
       if (!CurtainChecker.isEmpty(tmp)) {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveWindowIndex(tmp);
       }
       else {
         JOptionPane.showMessageDialog(null, "读取WindowIndex错误，请检查", "读文件错误", 0);
         return false;
       }

       tmp = orderinfo.getWoodoption();
       if (!CurtainChecker.isEmpty(tmp)) {
         int index = -1;
         for (int i = 0; i < Constants.WOODOPTION.length; i++) {
           if (Constants.WOODOPTION[i].equals(tmp)) {
             index = i;
             break;
           }
         }
         if (index > -1)
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveWoodOption(index);
       }
       else
       {
         JOptionPane.showMessageDialog(null, "读取HingeType错误，请检查", "读文件错误", 0);
         return false;
       }

       tmp = orderinfo.getColor();
       if (!CurtainChecker.isEmpty(tmp)) {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveColor(tmp);
       }
       else {
         JOptionPane.showMessageDialog(null, "读取Color错误，请检查", "读文件错误", 0);
         return false;
       }

       tmp = orderinfo.getOriwindowwidth();
       if (!CurtainChecker.isEmpty(tmp)) {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveOriWindowWidth(tmp);
       }
       else {
         JOptionPane.showMessageDialog(null, "读取OriWindowWidth错误，请检查", "读文件错误", 0);
         return false;
       }

       tmp = orderinfo.getOriwindowheight();
       if (!CurtainChecker.isEmpty(tmp)) {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveOriWindowHeight(tmp);
       }
       else {
         JOptionPane.showMessageDialog(null, "读取OriWindowHeight错误，请检查", "读文件错误", 0);
         return false;
       }

       tmp = orderinfo.getInstall();
       if (!CurtainChecker.isEmpty(tmp)) {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveInstall(tmp);
       }
       else {
         JOptionPane.showMessageDialog(null, "读取Install错误，请检查", "读文件错误", 0);
         return false;
       }

       tmp = orderinfo.getHingecolor();
       if (!CurtainChecker.isEmpty(tmp)) {
         int index = -1;
         for (int i = 0; i < Constants.HINGECOLOR.length; i++) {
           if (Constants.HINGECOLOR[i].equals(tmp)) {
             index = i;
             break;
           }
         }
         if (index > -1)
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveHingeColor(index);
       }
       else
       {
         JOptionPane.showMessageDialog(null, "读取Hinge Color错误，请检查", "读文件错误", 0);
         return false;
       }

       tmp = orderinfo.getPullbartype();
       if (!CurtainChecker.isEmpty(tmp)) {
         int index = -1;
         for (int i = 0; i < Constants.PULLBARTYPE.length; i++) {
           if (Constants.PULLBARTYPE[i].equals(tmp)) {
             index = i;
             break;
           }
         }
         if (index > -1) {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SavePullBarType(index);
         }

       }
       else if (!level.getBoard()) {
         JOptionPane.showMessageDialog(null, "读取PullBar错误，请检查", "读文件错误", 0);
         return false;
       }

       CurtainDesign.m_UserMainGUI.GetOrderInfo().saveAutoAddDivider(orderinfo.getAutoadddivider());

       boolean tmpbool = orderinfo.getBypasspanelconnected();
       CurtainDesign.m_UserMainGUI.GetOrderInfo().SavePanelConnected(tmpbool);

       tmpbool = level.getBoard();
       CurtainDesign.m_UserMainGUI.GetOrderInfo().saveIsBoard(tmpbool);

       tmp = level.getPanelnum();
       if (!CurtainChecker.isEmpty(tmp)) {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SavePanelNum(tmp);
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SavePoleNum(new Integer(tmp).toString());
       }
       else {
         JOptionPane.showMessageDialog(null, "读取PanelNum错误，请检查", "读文件错误", 0);
         return false;
       }

       tmp = orderinfo.getBypasstrack();
       if (!CurtainChecker.isEmpty(tmp)) {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().saveTrackNum(tmp);
       }
       else {
         JOptionPane.showMessageDialog(null, "读取TrackNum错误，请检查", "读文件错误", 0);
         return false;
       }

       tmp = level.getPolenum();
       if (!CurtainChecker.isEmpty(tmp)) {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SavePoleNum(tmp);
       }

       tmp = level.getVanetype();
       if (!CurtainChecker.isEmpty(tmp)) {
         int index = -1;
         for (int i = 0; i < Constants.VANETYPE.length; i++) {
           if (Constants.VANETYPE[i].equals(tmp)) {
             index = i;
             break;
           }
         }
         if (index > -1) {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveVaneType(index);
         }

       }
       else if (!level.getBoard()) {
         JOptionPane.showMessageDialog(null, "读取VaneType错误，请检查", "读文件错误", 0);
         return false;
       }

       tmp = level.getDividertype();
       if (!CurtainChecker.isEmpty(tmp)) {
         int index = -1;
         float fDividerWidth = new Float(tmp).floatValue();
         for (int i = 0; i < Constants.DIVIDERTYPE.length; i++)
         {
           if (new Float(Constants.DIVIDERTYPE[i]).floatValue() != fDividerWidth)
             continue;
           index = i;
           break;
         }

         if (index > -1)
         {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDividerType(index);
         }

       }
       else if ((!level.getBoard()) && (!CurtainChecker.isEmpty(level.getDividernum())))
       {
         int vanetype = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetVaneType();
         if ((vanetype == 0) || (vanetype == 2)) {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDividerType(2);
         }
         else if (vanetype == 1) {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDividerType(0);
         }
         else if (vanetype == 3)
         {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDividerType(1);
         }
         else
         {
           CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDividerType(3);
         }

       }

       tmp = level.getDividernum();
       if (!CurtainChecker.isEmpty(tmp)) {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDividerNum(tmp);
       }
       else {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDividerNum("0");
       }

       tmp = level.getDividerpos();
       if (tmp != null) {
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveDividerPos(tmp);
       }
       else if ((!level.getBoard()) && (!CurtainChecker.isEmpty(level.getDividernum())) && (Integer.parseInt(level.getDividernum()) == 0)) {
         JOptionPane.showMessageDialog(null, "读取DividerPos错误，请检查", "读文件错误", 0);
         return false;
       }

       Comments comments = orderinfo.getComments();
       if ((comments != null) &&
         (comments.getCommentArray() != null) && (comments.getCommentArray().length > 0)) {
         StringBuffer buff = new StringBuffer();
         int i = 0; for (int j = comments.getCommentArray().length; i < j; i++) {
           buff.append(comments.getCommentArray()[i]).append("@@");
         }
         CurtainDesign.m_UserMainGUI.GetOrderInfo().SaveComments(buff.toString());
       }
     }
     catch (Exception e)
     {
       e.printStackTrace();
     }
     return true;
   }

   public void WriteOrderFile(String orderfile, boolean newopenedfile, boolean override)
   {
     try {
       File xmlfile = new File(orderfile);
       OrderDocument doc = OrderDocument.Factory.newInstance();
       Orderinfo orderinfo = doc.addNewOrder();

       orderinfo.setWindowtype(Constants.STYLES[2]);
       Levelinfo level = orderinfo.addNewLevel();

       String tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetOrderIndex();
       orderinfo.setOrderindex(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetClientRegion();
       orderinfo.setClientregion(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetRoom();
       orderinfo.setRoom(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetPipeIndex();
       orderinfo.setPipeindex(tmpStr);

       Date tmpdate = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetOrderDate();
       DateFormat dtformat = new SimpleDateFormat("ddMMyyyy");
       orderinfo.setOrderdate(dtformat.format(tmpdate));

       tmpdate = new Date(tmpdate.getTime() + 691200000L);
       orderinfo.setDeliverdate(dtformat.format(tmpdate));

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().getCustRefNum();
       if (!CurtainChecker.isEmpty(tmpStr)) {
         orderinfo.setCustomerrefnum(tmpStr);
       }

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetWindowNum();
       orderinfo.setWindownum(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetWindowIndex();
       orderinfo.setWindowindex(tmpStr);

       int tmpint = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetWoodOption();
       if (tmpint > -1) {
         orderinfo.setWoodoption(Constants.WOODOPTION[tmpint]);
       }
       else {
         orderinfo.setWoodoption("");
       }

       orderinfo.setColor(CurtainDesign.m_UserMainGUI.GetOrderInfo().GetColor());

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetOriWindowWidth();
       orderinfo.setOriwindowwidth(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetOriWindowHeight();
       orderinfo.setOriwindowheight(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetInstall();
       orderinfo.setInstall(tmpStr);

       tmpint = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetHingeColor();
       if (!CurtainChecker.isEmpty(tmpStr)) {
         orderinfo.setHingecolor(Constants.HINGECOLOR[tmpint]);
       }
       else {
         orderinfo.setHingecolor("");
       }

       tmpint = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetPullBarType();
       if (tmpint > -1) {
         orderinfo.setPullbartype(Constants.PULLBARTYPE[tmpint]);
       }
       else {
         orderinfo.setPullbartype("");
       }

       orderinfo.setAutoadddivider(CurtainDesign.m_UserMainGUI.GetOrderInfo().getAutoAddDivider());

       boolean tmpbool = CurtainDesign.m_UserMainGUI.GetOrderInfo().IsPanelConnected();
       orderinfo.setBypasspanelconnected(tmpbool);

       tmpbool = CurtainDesign.m_UserMainGUI.GetOrderInfo().getIsBoard();
       level.setBoard(tmpbool);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetPanelNum();
       level.setPanelnum(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().getTrackNum();

       orderinfo.setBypasstrack(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetPoleNum();
       level.setPolenum(tmpStr);
       tmpint = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetVaneType();
       if (tmpint > -1) {
         level.setVanetype(Constants.VANETYPE[tmpint]);
       }
       else {
         level.setVanetype("");
       }

       tmpint = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetDividerType();
       if (tmpint > -1) {
         level.setDividertype(Constants.DIVIDERTYPE[tmpint]);
       }
       else {
         level.setDividertype("");
       }

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetDividerNum();
       level.setDividernum(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetDivederPos();
       level.setDividerpos(tmpStr);

       tmpStr = CurtainDesign.m_UserMainGUI.GetOrderInfo().GetComments();
       if (!CurtainChecker.isEmpty(tmpStr)) {
         Comments comment = orderinfo.addNewComments();
         comment.setCommentArray(tmpStr.split("@@"));
         orderinfo.setComments(comment);
       }
       Translator.chinese2English(orderinfo);
       doc.save(xmlfile);
     }
     catch (Exception e) {
       e.printStackTrace();
     }
   }
 }

/* Location:           C:\Users\Administrator\Desktop\奥特百叶窗\Shutter DesignerV3.1\CurtainDesign.jar
 * Qualified Name:     CurtainDesign.OrderFileByPass
 * JD-Core Version:    0.6.0
 */